package ch1.base.saveend;

/**
 * 结束线程
 * interrupt       仅仅中断
 * interrunped     既判断是否致公党，有由中断改为非中断
 * isInterrunpted  仅仅判断是否中断
 */
public class EndThread {

    //定义一个线程
    private static class UseThread extends Thread {
        UseThread(String threadName) {
            super(threadName);
        }

        @Override
        public void run() {
            String threadName = Thread.currentThread().getName();
            System.out.println(threadName + " interrupt flat：" + isInterrupted());
            System.out.println(threadName + " interrupt flat：" + interrupted());
            System.out.println(threadName + " interrupt flat：" + interrupted());

            while (!isInterrupted()) {
                System.out.println(threadName + "is running");
                System.out.println(threadName + "interrupt flag：" + isInterrupted());
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        UseThread useThread = new UseThread("endThread");
        useThread.start();

        Thread.sleep(20);
        useThread.interrupt();   //中断线程，其实设置线程的标示为为true
    }
}